package com.melon.service.impl;

import com.melon.entity.admin.User;
import com.melon.repository.UserRepository;
import com.melon.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by zhiqi.shao on 2017/3/15.
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Override
    public User save(User user) {
        return userRepository.save(user);
    }

    @Override
    public User getUser(Long id) {
        return userRepository.findOne(id);
    }

    @Override
    public User findUserByNamePswd(String username, String password) {
        return userRepository.findByUsernameAndPassword(username,password);
    }

    @Override
    public User findUserByUsername(String username){
        return userRepository.findByUsername(username);
    }

    @Override
    public void  deleteUserById(Long id){
        userRepository.delete(id);
    }

    @Override
    public List<User> findAll(){
       return  userRepository.findAll();
    }
}
